/**
 * 
 */
package bean;

import javax.servlet.http.HttpSession;

/**
 * The bean that is used to hold user parameters in session scope.
 * 
 * @author chuxiaoyuan
 * 
 */
public final class ParamBean {

	/**
	 * Constructor.
	 */
	public ParamBean() {
		// Initialize
	}

	/**
	 * The bean name.
	 */
	public static final String NAME = "ParamBean";

	/**
	 * Create a new parameter bean.
	 * 
	 * @param session
	 *            the http session.
	 * @return the new created parameter bean.
	 */
	public static ParamBean newParamBean(HttpSession session) {

		// Add new session attribute.
		ParamBean params = new ParamBean();
		session.setAttribute(NAME, params);
		return getParamBean(session);
	}

	/**
	 * Get parameter bean from session.
	 * 
	 * @param session
	 *            the http session.
	 * @return the bean. null if failed to get the bean.
	 */
	public static ParamBean getParamBean(HttpSession session) {

		// Get session attribute.
		Object bean = session.getAttribute(NAME);
		if (bean == null) {
			return null;
		}
		return (ParamBean)bean; 
	}

	/**
	 * Remove parameter bean from session.
	 * 
	 * @param session
	 *            the http session.
	 */
	public static void removeParamBean(HttpSession session) {

		// Remove entry.
		session.removeAttribute(NAME);
	}
	
	/**
	 * The login user profile.
	 */
	private UserProfile userProfile;

	/**
	 * Get the login user profile.
	 * 
	 * @return the userProfile
	 */
	public UserProfile getUserProfile() {
		return userProfile;
	}

	/**
	 * Set the login user profile.
	 * 
	 * @param userProfile the userProfile to set
	 */
	public void setUserProfile(UserProfile userProfile) {
		this.userProfile = userProfile;
	}

}
